package com.xiaoxin.experience.api.config;

import com.xiaoxin.experience.common.Property;
import com.xiaoxin.experience.common.BaseResponse;
import com.xiaoxin.experience.system.properties.BeanValueUtil;
import com.xiaoxin.experience.system.properties.PropertiesHelper;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Properties;

/**
 * @author xiaoxin
 */
@RestController
@RequestMapping("/api/system")
public class SystemPropertiesController
{
    @Resource
    BeanValueUtil beanValueUtil;

    @RequestMapping("/set")
    public BaseResponse setProperties(@RequestBody Property property)
    {
        if (PropertiesHelper.cacheProperty(property))
        {
            Properties properties = new Properties();
            properties.setProperty(property.getKey(),property.getValue());
            beanValueUtil.refreshValue(properties);
            beanValueUtil.handleLoggerLevel(properties);
        }
        return new BaseResponse();
    }
}
